package com.log530_projetfinal;

import java.util.Random;

import android.graphics.Point;


public class utile
{

  public utile()
  {
  }

  static public double distanceEntrePoint(Point primo, Point secundo)
  {
    int distanceX = primo.x - secundo.x;
    int distanceY = primo.y - secundo.y;

    return Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
  }

  static public Point calculatePoint(int maxX, int maxY, Random r)
  {
    int x = Math.abs((r.nextInt() % maxX));
    int y = Math.abs((r.nextInt() % maxY));
    Point p = new Point(x, y);

    return p;
  }

  static public boolean ptOutCircle(Point p1, int diametre1, Point p2,
                                    int diametre2)
  {

    double distanceAutrePoint, espacmentEntrePoint;
    int coterX = p1.x - p2.x;
    int coterY = p1.y - p2.y;

    distanceAutrePoint =
        Math.sqrt(Math.pow(coterX, 2) + Math.pow(coterY, 2));
    espacmentEntrePoint = diametre1 / 2 + diametre2 / 2;

    if (distanceAutrePoint >= espacmentEntrePoint)
    {
      return true;
    }
    else
      return false;
  }

  static public Point genPtInCircle(Point centre, int range, Random r)
  {
    boolean accepter = false;
    double distanceDuCentre;

    int x = 0, y = 0, coterX, coterY;

    while (!accepter)
    {

      x = (r.nextInt() % range);
      y = (r.nextInt() % range);

      //System.out.println(x +"/"+ y+"/"+range);

      coterX = x;
      coterY = y;

      distanceDuCentre =
          Math.sqrt(Math.pow(coterX, 2) + Math.pow(coterY, 2));

      if (distanceDuCentre <= range)
      {
        accepter = true;
      }
    }

    Point p = new Point(x + centre.x, y + centre.y);
    return p;
  }

  static public double getAngleEntreElement(Point cible, Point where)
  {

    int adj = where.x - cible.x; //si positif == a gauche sinon droite
    int opp = where.y - cible.y; //si positif == a top sinon bottom


    double angle = Math.abs(Math.atan(opp / adj) * 180 / Math.PI);

    System.out.println(angle + "/" + adj + "/" + opp);

    if (adj > 0 && opp < 0)
    {
      angle = 90 - angle;
    }
    else if (adj >= 0 && opp >= 0)
    {
      angle += 90;
    }
    else if (adj < 0 && opp >= 0)
    {
      angle = 180 + (90 - angle);
    }
    else
    {
      angle += 270;
    }
    System.out.println(angle);
    return angle;
  }
}
